package com.hbvtc.xxxy.nikeSale.frames;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import com.hbvtc.xxxy.nikeSale.daos.Vipdao;
import com.hbvtc.xxxy.nikeSale.models.Vips;

/*
 * 添加会员信息
 */
public class AddVipNike extends JFrame implements ActionListener {
	JButton jButton;
	JLabel jLabel1, jLabel2, jLabel3, jLabel4;
	JTextField jt1, jt2, jt3, jt4;
	String id, pwd, name;
	double price;
	Vips vips = new Vips();

	public AddVipNike() {
		this.setTitle("会员注册界面");
		this.setSize(1000, 700);
		this.setLocationRelativeTo(null);
		this.setVisible(true);

		// 设置标题栏的图标
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("01.png"));
		this.setIconImage(imageIcon.getImage());
		// 背景图片的路径
		String path = "images/001.jpg";
		ImageIcon background = new ImageIcon(path);
		// 把背景图片显示在一个标签里面
		JLabel label = new JLabel(background);
		// 把标签的大小位置设置为图片刚好填充整个面板
		label.setBounds(0, 0, this.getWidth(), this.getHeight());
		// 把内容窗格转化为JPanel，否则不能用方法setOpaque()来使内容窗格透明
		JPanel imagePanel = (JPanel) this.getContentPane();
		imagePanel.setOpaque(false);
		// 把背景图片添加到分层窗格的最底层作为背景
		this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
		
//		jPanel = new JPanel();
		this.setLayout(null);
//		setContentPane(jPanel);
		jLabel1 = new JLabel("会员电话：");
		jLabel2 = new JLabel("会员姓名：");
		jLabel3 = new JLabel("会员密码：");
		jLabel4 = new JLabel("会员金额：");
		jButton = new JButton("立即添加");
		jt1 = new JTextField();
		jt2 = new JTextField();
		jt3 = new JTextField();
		jt4 = new JTextField();
		this.add(jLabel1);
		this.add(jLabel2);
		this.add(jLabel3);
		this.add(jLabel4);
		this.add(jButton);
		this.add(jt1);
		this.add(jt2);
		this.add(jt3);
		this.add(jt4);

		jLabel1.setBounds(150, 100, 120, 30);
		jLabel1.setFont(new Font(null, 0, 24));
		jLabel2.setBounds(150, 200, 120, 30);
		jLabel2.setFont(new Font(null, 0, 24));
		jLabel3.setBounds(150, 300, 120, 30);
		jLabel3.setFont(new Font(null, 0, 24));
		jLabel4.setBounds(150, 400, 120, 30);
		jLabel4.setFont(new Font(null, 0, 24));
		
		jt1.setBounds(400, 100, 250, 30);
		jt1.setFont(new Font(null, 0, 24));
		jt2.setBounds(400, 200, 250, 30);
		jt2.setFont(new Font(null, 0, 24));
		jt3.setBounds(400, 300, 250, 30);
		jt3.setFont(new Font(null, 0, 24));
		jt4.setBounds(400, 400, 250, 30);
		jt4.setFont(new Font(null, 0, 24));
		jButton.setBounds(580, 550, 150, 40);
		jButton.setFont(new Font(null, 0, 24));

		jButton.addActionListener(this);
	}

	public static void main(String[] args) {
		new AddVipNike().setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		id = jt1.getText();
		name = jt2.getText();
		pwd = jt3.getText();
		price = Integer.parseInt(jt4.getText());
		try {
			vips.setTelephone(id);
			vips.setName(name);
			vips.setPwd(pwd);
			vips.setBalance(price);
			Vipdao vipdao = new Vipdao();
			try {
				if (vipdao.sss(id) == false) {
					vipdao.addshanpin(vips);
					JOptionPane.showMessageDialog(AddVipNike.this, "会员注册成功");
				} else {
					JOptionPane.showMessageDialog(AddVipNike.this, "会员注册失败");
				}
			} catch (SQLException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		} catch (NumberFormatException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
	}
}
